package com.hqyj.springboot.modules.common.service.impl;

import com.hqyj.springboot.modules.common.dao.ExceptionLogDao;
import com.hqyj.springboot.modules.common.entity.ExceptionLog;
import com.hqyj.springboot.modules.common.service.ExceptionLogService;
import com.hqyj.springboot.modules.common.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import java.time.LocalDateTime;

@Service
public class ExceptionLogServiceImpl implements ExceptionLogService {
    @Autowired
    private ExceptionLogDao exceptionLogDao;


    @Override
    @Transactional
    public Result<ExceptionLog> insertExceptionLog(ExceptionLog exceptionLog) {
        ExceptionLog temp = exceptionLogDao.getELByPathAndName(exceptionLog.getPath(),exceptionLog.getExceptionType());
        if (temp != null){
            return new Result<ExceptionLog>(Result.ResultStatus.SUCCESS.code, "异常信息已经存在!");
        }

        exceptionLog.setCreateDate(LocalDateTime.now());
        exceptionLog.setUpdateDate(LocalDateTime.now());

        exceptionLogDao.insertExceptionLog(exceptionLog);
        return new Result<ExceptionLog>(Result.ResultStatus.SUCCESS.code, "插入成功!",exceptionLog);
    }
}
